package com.cmc.cloud.cmclink.doc.mq;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 生产者
 *
 * @author huzheng
 * @date 2025/09/16 13:36
 **/
@Component
public class MyProducer {
    @Autowired
    private RocketMQTemplate rocketMqTemplate;

    /**
     * 发送普通消息到指定主题
     *
     * @param topic   topic
     * @param message message
     */
    public void sendMessage(String topic, Object message) {
        rocketMqTemplate.convertAndSend(topic, message);
    }

    /**
     * 发送带标签（Tag）的消息，用于消息过滤
     *
     * @param topic   topic
     * @param tag     tag
     * @param message message
     */
    public void sendMessageWithTag(String topic, String tag, Object message) {
        rocketMqTemplate.convertAndSend(topic + ":" + tag, message);
    }
}
